/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketbooking;

import DBTransmit.TableAdminRecord;
import DBTransmit.TableChuyenTauRecord;
import DBTransmit.TableDSDKRecord;
import DBTransmit.TableGaRecord;
import DBTransmit.TableUserRecord;
import MessageVariable.BookedTicket;
import MessageVariable.ResponseFromServer;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author LEHOANGKHANH
 */
public class Utils {
    public static void LoadDataToTable(JTable tb, List data){
         if(tb == null || data== null){
             return;
         }
         DefaultTableModel model = (DefaultTableModel) tb.getModel();
         Object objType = data.get(0);
         if(objType instanceof ResponseFromServer){  
            for(int i=0; i<data.size(); i++){
                ResponseFromServer row = (ResponseFromServer)data.get(i);
                model.addRow(new Object[]{row.getMaCT(), row.getGaDi(), row.getGaDen(), row.getNgayKhoiHanh(), row.getGioKhoiHanh(), row.getSLVeConLai()});
            }
         }
         if(objType instanceof BookedTicket){
             for(int i=0; i<data.size(); i++){
                 BookedTicket row = (BookedTicket)data.get(i);
                 model.addRow(new Object[]{row.getMaCT(), row.getGaDi(), row.getGaDen(), row.getNgayKhoiHanh(), row.getGioKhoiHanh(), row.getSLVeDaDat()});
             }
         }
         if(objType instanceof TableUserRecord){
             for(int i=0; i<data.size(); i++){
                 TableUserRecord row = (TableUserRecord)data.get(i);
                 model.addRow(new Object[]{row.getUserName(), row.getPassWord(), row.getFullName(), row.getDiaChi(), row.getSDT(), row.getCMND(), row.getTKNH()});
             }
         }
         if(objType instanceof TableGaRecord){
             for(int i=0; i<data.size(); i++){
                 TableGaRecord row = (TableGaRecord)data.get(i);
                 model.addRow(new Object[]{row.getMaGa(), row.getTenGa(), row.getDiaDiem()});
             }
         }
         if(objType instanceof TableChuyenTauRecord){
             for(int i=0; i<data.size(); i++){
                 TableChuyenTauRecord row = (TableChuyenTauRecord)data.get(i);
                 model.addRow(new Object[]{row.getMaCT(), row.getGaDi(), row.getGaDen(), row.getNgayKhoiHanh(), row.getGioKhoiHanh(), row.getSLVe(), row.getSLVeTK()});
             }
         }
         if(objType instanceof TableDSDKRecord){
             for(int i=0; i<data.size(); i++){
                 TableDSDKRecord row = (TableDSDKRecord)data.get(i);
                 model.addRow(new Object[]{row.getID(), row.getUserName(), row.getMaCT(), row.getSLVe()});
             }
         }
         if(objType instanceof TableAdminRecord){
             for(int i=0; i<data.size(); i++){
                 TableAdminRecord row = (TableAdminRecord)data.get(i);
                 model.addRow(new Object[]{row.getUserName(), row.getPassWord()});
             }
         }    
    }
    public static void LoadDataToComboBox(JComboBox box, List<String> lst){
         if(box == null || lst== null){
             return;
         }
         for(int i=0; i<lst.size(); i++){
             box.addItem(lst.get(i));
         }
    }
}
